package cn.wolfcode.luowowo.website.web.controller;

import cn.wolfcode.luowowo.cache.service.IUserInfoRedisService;
import cn.wolfcode.luowowo.member.service.IUserInfoService;
import cn.wolfcode.luowowo.website.util.UploadUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

@Controller
public class UploadController {

    @Reference
    private IUserInfoRedisService userInfoRedisService;
    @Reference
    private IUserInfoService userInfoService;

    @Value("${file.path}")
    private String filePath;

    @RequestMapping("/coverImageUpload")
    @ResponseBody  //插件要求这么写的
    public  Object uploadImg(MultipartFile pic){
        String filename = UploadUtil.upload(pic,filePath );
        return filename;
    }




//    @RequestMapping("/uploadImg_ck")
//    @ResponseBody
//    public Map<String, Object> upload(MultipartFile upload, String module){
//        Map<String, Object> map = new HashMap<String, Object>();
//        String imagePath= null;
//        if(upload != null && upload.getSize() > 0){
//            try {
//                //图片保存, 返回路径
//                imagePath =  UploadUtil.upload(upload,filePath );
//                //表示保存成功
//                map.put("uploaded", 1);
//                map.put("url", "/" + imagePath);
//
//            }catch (Exception e){
//                e.printStackTrace();
//                map.put("uploaded", 0);
//                Map<String, Object> mm = new HashMap<String, Object>();
//                mm.put("message",e.getMessage() );
//                map.put("error", mm);
//            }
//        }
//        return map;
//    }

}
